﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UtilityLibrary.WinControls;
using V5_Apps.Core;
using WeifenLuo.WinFormsUI.Docking;

namespace V5_Apps.Forms {
    public partial class frmTreeBox : DockContent {


        public delegate void OutTreeNodeOption(string pluginInfo);
        public OutTreeNodeOption OutTNO;
        private OutlookBar outlookBarLeftTree = null;
        private TreeView tv = new TreeView();
        public frmTreeBox() {
            InitializeComponent();

            outlookBarLeftTree = new OutlookBar();
            //OutlookBarBand outlookShortcutsBand = new OutlookBarBand("工具列表");
            //outlookShortcutsBand.SmallImageList = this.imageList_Icons;
            //outlookShortcutsBand.LargeImageList = this.imageList_Icons;
            //outlookShortcutsBand.Items.Add(new OutlookBarItem("博客地址管理", 0, "1"));
            //outlookShortcutsBand.Items.Add(new OutlookBarItem("关键字管理", 0, "1"));
            //outlookShortcutsBand.Items.Add(new OutlookBarItem("书籍管理", 0, "1"));
            //outlookShortcutsBand.Items.Add(new OutlookBarItem("自动发送文章设置", 0, "1"));
            //outlookShortcutsBand.Items.Add(new OutlookBarItem("日志管理", 0, "1"));
            //outlookShortcutsBand.Background = SystemColors.AppWorkspace;
            //outlookShortcutsBand.TextColor = Color.White;
            //outlookBarLeftTree.Bands.Add(outlookShortcutsBand);
            //
            outlookBarLeftTree.Bands.Add(new OutlookBarBand("TreeView", tv));
            //
            outlookBarLeftTree.Dock = DockStyle.Fill;
            outlookBarLeftTree.SetCurrentBand(0);
            this.Controls.AddRange(new Control[] { outlookBarLeftTree });
        }

        private void frmTreeBox_Load(object sender, EventArgs e) {
            Bind_LoadTree();
        }
        /// <summary>
        /// 添加节点
        /// </summary>
        public void AddNode(string text, string path, string commond, string runTime) {
            var tn = new TreeNode() {
                Text = text,
                Tag = text + "||" + path + "||" + commond + "||" + runTime
            };
            tv.Nodes.Add(tn);
            tv.AfterSelect += tv_AfterSelect;
        }

        void tv_AfterSelect(object sender, TreeViewEventArgs e) {
            TreeNode node = e.Node;
            if (node != null && node.Tag != null) {
                string sData = node.Tag.ToString();
                //string[] arrData = sData.Split(new string[] { "||" }, StringSplitOptions.None);
                if (OutTNO != null) {
                    OutTNO(sData);
                }
            }
        }

        public void Bind_LoadTree() {
            var listPlugin = PluginHelper.Instance.LoadAllPluginList();
            foreach (var m in listPlugin) {
                AddNode(m.Text, m.PluginDir, m.Commond, m.RunTime);
            }
        }
    }
}
